package com.wencst.generateJPA.builder.json.impl;

import java.util.ArrayList;
import java.util.List;

import com.wencst.generateJPA.bean.TransferBean;
import com.wencst.generateJPA.builder.json.AbstractJsonBuilder;
import com.wencst.generateJPA.config.CoreContext;
import com.wencst.generateJPA.utils.StringUtils;
import com.wencst.security.bean.Menu;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MenuBuilder extends AbstractJsonBuilder {

	public MenuBuilder(CoreContext coreContext) {
		super(coreContext);
		// TODO Auto-generated constructor stub
	}

	@Override
	public String getFileName() {
		return "menus.json";
	}

	@Override
	protected void addDataInto(TransferBean tb) {
		List<Menu> menus = getContentAsList(Menu.class);
		if (menus == null) {
			menus = new ArrayList<Menu>();
		}
		Menu menu = generalMenu(tb);
		menus.add(menu);
		writeIntoFile(menus);
		log.info("add data info {}",tb.getTableName());
	}
	
	private Menu generalMenu(TransferBean tb) {
		Menu menu = new Menu();
		String comment = tb.getComment();
		if (StringUtils.isBlank(comment)) {
			comment = tb.getJavaBeanName();
		}
		menu.setName(comment);
		menu.setPage("/"+tb.getJavaBeanName()+"/listPage.html");
		return menu;
	}

}
